package com.upstairstechnology.oi.notification.email;

import javax.mail.Address;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

import org.springframework.beans.factory.annotation.Required;

import com.upstairstechnology.oi.notification.NotificationConfiguration;

/**
 * Configuration properties for email notification.
 * 
 * @author Jeff Jensen
 */
public class NotificationConfigurationEmail implements
        NotificationConfiguration {
    /** Name of the resource file containing javax.mail properties. */
    private String mailPropertiesResourceName;

    /** Array of CC email addresses . */
    private Address[] ccAddresses;

    /** Email's subject. */
    private String subject;

    /**
     * Set the address array from a string array.
     * 
     * @param addresses
     *            The string array of addresses.
     * @throws AddressException
     *             When errors occur with address parsing.
     */
    @Required
    public void setCcAddressesStrArray(String[] addresses)
            throws AddressException {
        int len = addresses.length;
        ccAddresses = new Address[len];
        for (int i = 0; i < len; i++) {
            String addressStr = addresses[i];
            Address address = new InternetAddress(addressStr);
            ccAddresses[i] = address;
        }
    }

    /**
     * Get the mailPropertiesResourceName.
     * 
     * @see {@link mailPropertiesResourceName}.
     * 
     * @return The mailPropertiesResourceName.
     */
    public String getMailPropertiesResourceName() {
        return mailPropertiesResourceName;
    }

    /**
     * Set the mailPropertiesResourceName.
     * 
     * @see {@link mailPropertiesResourceName}.
     * 
     * @param name
     *            The mailPropertiesResourceName to set.
     */
    @Required
    public void setMailPropertiesResourceName(String name) {
        this.mailPropertiesResourceName = name;
    }

    /**
     * Get the ccAddresses.
     * 
     * @see {@link ccAddresses}.
     * 
     * @return The ccAddresses.
     */
    public Address[] getCcAddresses() {
        return ccAddresses;
    }

    /**
     * Set the ccAddresses.
     * 
     * @see {@link ccAddresses}.
     * 
     * @param addresses
     *            The ccAddresses to set.
     */
    public void setCcAddresses(Address[] addresses) {
        this.ccAddresses = addresses;
    }

    /**
     * Get the subject.
     * 
     * @see {@link subject}.
     * 
     * @return The subject.
     */
    public String getSubject() {
        return subject;
    }

    /**
     * Set the subject.
     * 
     * @see {@link subject}.
     * 
     * @param emailSubject
     *            The subject to set.
     */
    @Required
    public void setSubject(String emailSubject) {
        this.subject = emailSubject;
    }
}
